@@ -24,7 +24,7 @@ class AdminPanelController < ApplicationController |
||
24 | 24 |
end |
25 | 25 |
|
26 | 26 |
def contact_messages |
27 |
- @contact_messages = ContactMessage.order('created_at DESC').all |
|
27 |
+ @contact_messages = ContactMessage.order('created_at DESC').to_a |
|
28 | 28 |
end |
29 | 29 |
|
30 | 30 |
def show_contact_message |
@@ -15,9 +15,10 @@ class ContactMessagesController < ApplicationController |
||
15 | 15 |
@contact_message.user = current_user |
16 | 16 |
end |
17 | 17 |
@contact_message.unread = true |
18 |
+ to_address = Info.first.contact_email |
|
18 | 19 |
respond_to do |format| |
19 | 20 |
if @contact_message.save |
20 |
- UserMailer.contact_message(@contact_message).deliver |
|
21 |
+ UserMailer.contact_message(@contact_message, to_address).deliver |
|
21 | 22 |
format.html { redirect_to contact_messages_path, notice: (t 'contact.delivered') } |
22 | 23 |
format.json { render action: 'show', status: :created, location: @contact_message } |
23 | 24 |
else |
@@ -1,14 +1,14 @@ |
||
1 | 1 |
class UserMailer < ActionMailer::Base |
2 |
- default from: "from@example.com" |
|
2 |
+ default from: "contact@website.com" |
|
3 | 3 |
|
4 | 4 |
|
5 |
- def contact_message(contact_message) |
|
6 |
- @config = Info.first |
|
5 |
+ def contact_message(contact_message, to_address) |
|
7 | 6 |
@msg = contact_message |
8 |
- mail :subject => @msg.title, |
|
9 |
- :to => @config.contact_email, |
|
10 |
- :from => @msg.email, |
|
11 |
- :from_name => @msg.name |
|
7 |
+ mail :to => to_address, |
|
8 |
+ :subject => @msg.title, |
|
9 |
+ :from => @msg.user == nil ? @msg.email : @msg.user.email, |
|
10 |
+ :from_name => @msg.user != nil ? @msg.user.full_name : @msg.email, |
|
11 |
+ :body => @msg.content |
|
12 | 12 |
end |
13 | 13 |
|
14 | 14 |
end |
@@ -35,6 +35,6 @@ RailsWebsiteTemplate::Application.configure do |
||
35 | 35 |
config.active_support.deprecation = :stderr |
36 | 36 |
|
37 | 37 |
# Crapy Fix for email testing error |
38 |
- config.action_mailer.raise_delivery_errors = false |
|
38 |
+ config.action_mailer.raise_delivery_errors = true |
|
39 | 39 |
|
40 | 40 |
end |
@@ -5,7 +5,8 @@ Feature: Admin Panel |
||
5 | 5 |
I want to config the website thru an admin panel |
6 | 6 |
|
7 | 7 |
Background: |
8 |
- Given the following blog_post list |
|
8 |
+ Given the website is configured |
|
9 |
+ And the following blog_post list |
|
9 | 10 |
| title | content | published | description | slug | |
10 | 11 |
| Hello World | Welcome to the website | true | First Post | hello_world | |
11 | 12 |
| Test 001 | 1 2 3 testing | true | Testing the website | test_001 | |
@@ -46,9 +47,9 @@ Feature: Admin Panel |
||
46 | 47 |
When I go to the configurations page |
47 | 48 |
Then I should see "You dont have permission to access that page!" |
48 | 49 |
|
49 |
- @focus |
|
50 | 50 |
Scenario: Change the website name and Tagline |
51 | 51 |
Given I am logged in as admin |
52 |
+ And I should see "Rails Website Template" |
|
52 | 53 |
When I go to the configurations page |
53 | 54 |
Then I fill in "info_website_name" with "Testing Website Name" |
54 | 55 |
And I fill in "info_tagline" with "Just another cucumber test" |
@@ -1,10 +1,12 @@ |
||
1 |
+@blog |
|
1 | 2 |
Feature: Blog Posts |
2 | 3 |
In order to make a blog |
3 | 4 |
As an author |
4 | 5 |
I want to create and manage blog psots |
5 | 6 |
|
6 | 7 |
Background: |
7 |
- Given the following blog_post list |
|
8 |
+ Given the website is configured |
|
9 |
+ And the following blog_post list |
|
8 | 10 |
| title | content | published | description | slug | |
9 | 11 |
| Hello World | Welcome to the website | true | First Post | hello_world | |
10 | 12 |
| Test 001 | 1 2 3 testing | true | Testing the website | test_001 | |
@@ -1,8 +1,17 @@ |
||
1 |
+@contact_messages |
|
1 | 2 |
Feature: Contact Messages |
3 |
+ |
|
2 | 4 |
In order to send a message |
3 | 5 |
As an visitor |
4 | 6 |
I want to send contact messages |
5 | 7 |
|
8 |
+ In order to receive a messages from visitors |
|
9 |
+ As the site administrator |
|
10 |
+ I want to receive and access contact messages |
|
11 |
+ |
|
12 |
+ Background: |
|
13 |
+ Given the website is configured |
|
14 |
+ |
|
6 | 15 |
Scenario: Send Contact Message as a visitor |
7 | 16 |
Given I go to the homepage |
8 | 17 |
When I go to the contact page |
@@ -11,7 +20,8 @@ Feature: Contact Messages |
||
11 | 20 |
And I fill in "contact_message_title" with "Hello Webmaster" |
12 | 21 |
And I fill in "contact_message_content" with "How are you doing bro?" |
13 | 22 |
And I click in the button "submit_contact_message" |
14 |
- Then I should see "Message sent!" |
|
23 |
+ Then I should see "Message sent!" |
|
24 |
+ And "admin@website.com" should receive an email with subject "Hello Webmaster" |
|
15 | 25 |
|
16 | 26 |
Scenario: Send Contact Message as a user |
17 | 27 |
Given I am logged in as user |
@@ -23,3 +33,17 @@ Feature: Contact Messages |
||
23 | 33 |
And I fill in "contact_message_content" with "How are you doing bro?" |
24 | 34 |
And I click in the button "submit_contact_message" |
25 | 35 |
Then I should see "Message sent!" |
36 |
+ And "admin@website.com" should receive an email with subject "Hello Webmaster" |
|
37 |
+ |
|
38 |
+ @focus |
|
39 |
+ Scenario: Receive message |
|
40 |
+ Given I go to the contact page |
|
41 |
+ And I fill in "contact_message_email" with "yo@website.com" |
|
42 |
+ And I fill in "contact_message_title" with "Hello Webmaster" |
|
43 |
+ And I fill in "contact_message_content" with "How are you doing bro?" |
|
44 |
+ And I click in the button "submit_contact_message" |
|
45 |
+ Then I should see "Message sent!" |
|
46 |
+ And "admin@website.com" should receive an email with subject "Hello Webmaster" |
|
47 |
+ Then I log in as admin |
|
48 |
+ And I go to the contact messages list |
|
49 |
+ And I should see "Hello Webmaster" |
@@ -1,7 +1,5 @@ |
||
1 | 1 |
include Warden::Test::Helpers |
2 | 2 |
|
3 |
-Info.create( :website_name => 'Website', :tagline => 'A Ruby on Rails app template', :default_language => 'en' ) |
|
4 |
- |
|
5 | 3 |
Given /^the following (.+) list ?$/ do |factory, table| |
6 | 4 |
user = FactoryGirl.create(:user) |
7 | 5 |
table.hashes.each do |hash| |
@@ -57,6 +57,9 @@ Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amou |
||
57 | 57 |
end |
58 | 58 |
|
59 | 59 |
Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject| |
60 |
+ # @email = ActionMailer::Base.deliveries.last |
|
61 |
+ # @email.to.should include address |
|
62 |
+ # @email.subject.should subject |
|
60 | 63 |
unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount) |
61 | 64 |
end |
62 | 65 |
|
@@ -1,4 +1,12 @@ |
||
1 | 1 |
Then(/^I should see in the field "(.*?)" the text "(.*?)"$/) do |arg1, arg2| |
2 | 2 |
value = find_field(arg1).value |
3 | 3 |
value.should have_content(arg2) |
4 |
+end |
|
5 |
+ |
|
6 |
+Given(/^the website is configured$/) do |
|
7 |
+ configs = Info.all |
|
8 |
+ configs.each do |config| |
|
9 |
+ config.destroy |
|
10 |
+ end |
|
11 |
+ FactoryGirl.create(:info) |
|
4 | 12 |
end |
@@ -61,4 +61,8 @@ require "#{Rails.root}/spec/factories.rb" |
||
61 | 61 |
require 'email_spec' # add this line if you use spork |
62 | 62 |
require 'email_spec/cucumber' |
63 | 63 |
|
64 |
+ActionMailer::Base.delivery_method = :test |
|
65 |
+ActionMailer::Base.perform_deliveries = true |
|
66 |
+ActionMailer::Base.deliveries.clear |
|
67 |
+ |
|
64 | 68 |
|
@@ -19,6 +19,9 @@ module NavigationHelpers |
||
19 | 19 |
when/the contact page/ |
20 | 20 |
visit contact_messages_path |
21 | 21 |
|
22 |
+ when/the contact messages list/ |
|
23 |
+ visit admin_contact_messages_path |
|
24 |
+ |
|
22 | 25 |
when/the admin blog posts page/ |
23 | 26 |
visit admin_posts_path |
24 | 27 |
|
@@ -25,5 +25,14 @@ FactoryGirl.define do |
||
25 | 25 |
f.description "foobar is cool" |
26 | 26 |
end |
27 | 27 |
|
28 |
+ factory :info do |
|
29 |
+ website_name 'Rails Website Template' |
|
30 |
+ tagline 'A Ruby on Rails app template' |
|
31 |
+ default_language 'en' |
|
32 |
+ contact_email 'admin@website.com' |
|
33 |
+ server_email 'no-reply@website.com' |
|
34 |
+ website_link 'http://localhost:3000' |
|
35 |
+ end |
|
36 |
+ |
|
28 | 37 |
end |
29 | 38 |
|
@@ -0,0 +1,16 @@ |
||
1 |
+require 'spec_helper' |
|
2 |
+ |
|
3 |
+describe UserMailer do |
|
4 |
+ include EmailSpec::Helpers |
|
5 |
+ include EmailSpec::Matchers |
|
6 |
+ |
|
7 |
+ describe '.invite_requested' do |
|
8 |
+ let(:contact_message) { Factory.build :contact_message, :email => 'someone@someco.com' } |
|
9 |
+ |
|
10 |
+ describe 'one email to one user' do |
|
11 |
+ subject { InviteMailer.invite_requested(invite) } |
|
12 |
+ it { should deliver_to invite.email } |
|
13 |
+ it { should deliver_from 'alex@awesome-startup.com' } |
|
14 |
+ end |
|
15 |
+ end |
|
16 |
+end |